package com.talent.service.impl;

import com.talent.dao.MajorMapper;
import com.talent.page.Page;
import com.talent.pojo.Major;
import com.talent.service.MajorService;
import com.talent.vo.MajorDepartVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MajorServiceImpl implements MajorService {


    @Autowired
    MajorMapper majorMapper;

    @Override
    public int addMajor(Major major) {
        return majorMapper.insertSelective(major);
    }

    @Override
    public Page<Major> selectMajorPage(Major major, int currentPage) {
        Page<Major> page = new Page<>(currentPage, Page.DEFAULT_PAGE_SIZE);
        List<Major> majorList = majorMapper.selectMajorPage(major, page);
        page.setResultList(majorList);
        return page;
    }

    @Override
    public Major selectById(Integer id) {
        return majorMapper.selectByPrimaryKey(id);
    }

    @Override
    public int editMajor(Major major) {
        return majorMapper.updateByPrimaryKeySelective(major);
    }

    @Override
    public int deleteById(Integer id) {
        return majorMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Page<MajorDepartVo> selectMajorDepartVoPage(MajorDepartVo majorDepartVo, int currentPage) {
        Page<MajorDepartVo> page = new Page<>(currentPage, Page.DEFAULT_PAGE_SIZE);
        List<MajorDepartVo> majorDepartVoList = majorMapper.selectMajorDepartVoPage(majorDepartVo, page);
        page.setResultList(majorDepartVoList);
        return page;
    }

    @Override
    public int validate(String name) {
        return majorMapper.validate(name);
    }

    @Override
    public void deleteAll(String[] ids) {
        majorMapper.deleteAll(ids);
    }

    @Override
    public List<Major> selectAllMajor() {
        return majorMapper.selectAllMajor();
    }

    @Override
    public MajorDepartVo selectMajorDepartById(Integer id) {
        return majorMapper.selectMajorDepartById(id);
    }
		@Override
	public Integer selectIdByMajorName(String majorName) {
		return majorMapper.selectIdByMajorName(majorName);
	}
}
